package com.shumei.servlet.productservlet;

import com.shumei.DAO.ProductDAO;
import com.shumei.DAO.impl.ProductDAOImpl;
import com.shumei.pojo.Product;
import com.shumei.servlet.ViewBaseServlet;
import com.shumei.util.Util;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/productdelete")
public class MProductDelServlet extends HttpServlet {
    private ProductDAO productDA0 = new ProductDAOImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 获取发送的信息
        String pid = req.getParameter("pid");
        //判断字符串是否合法(使用工具类)
        if(Util.isEmpty(pid)) {
            throw new RuntimeException("字符串为空！");
        }
        Boolean product = productDA0.deleteProduct(Integer.valueOf(pid));
        resp.sendRedirect("/jw1/mproductindex");
//        req.setAttribute("product
//        ", product);
//        // 将请求转发到edit视图上
//        super.processTemplate("/admin/detail",req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }
}